<template>
	<view class="content ffffff padding">
		<view class="flexbetween">
			<view class="color_ling text_x">
				<text class="">
					添加参数
				</text>
				<text class="slys" @click="toyonghuxy" style="text-decoration: underline;color: #F3271C;">
					(请点此处查看示例)<image src="@/static/image/shoushi.png" style="width:28rpx;height: 28rpx;display: position: relative;top: 8rpx;" mode=""></image>
				</text>
			</view>
			<!-- <view class="imgBox">
				<image src="/static/image/home/add.png" mode=""></image>
			</view> -->
			<view class="text_five" style="color: #F3271C;" @click="addMsg">添加</view>
		</view>
		<view class="margin_top padding f7f7f7 margin_bottom3" v-for="(item,index) in param" :key="index">
			<view>
				<input class="text_a" type="text" placeholder="1.参数名称:“材质”" placeholder-style="font-size: 28rpx;font-weight: 500;color: #999999;" v-model="item.key">
			</view>
			<view class="flexbetween margin_top">
				<input class="text_a" style="color: #F3271C;" type="text" placeholder="2.参数描述:“真丝面料等”" placeholder-style="font-size: 28rpx;font-weight: 500;color: #F3271C;" v-model="item.value">
				<image class="imgDelete" src="/static/image/mine/delete.png" mode="" @click="del(index)"></image>
			</view>
		</view>
		<!-- 底部 -->
		<view class="footer ffffff padding">
			<view class="footerButton" @click="save">保存</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data(){
			return {
				param: [{
					key:"",
					value:"",
				}],
			}
		},
		onLoad(options) {
			this.param = JSON.parse(decodeURIComponent(options.msg));
		},
		watch:{
			param(newval){
				if(newval.length==0){
					this.addMsg()
				}
			}
		},
		methods:{
			//跳转用户协议
			toyonghuxy() {
				uni.navigateTo({
					url: '/pages_mine/aboutWe?type=5'
				})
			},
			addMsg(){
				this.param.push({
					key:"",
					value:""
				})
			},
			del(index){
				this.param.splice(index,1)
			},
			save(){
				let arr = JSON.parse(JSON.stringify(this.param))
				arr.forEach((item, index) => {
					if (item.key == "" || item.value == "") {
						arr.splice(index, 1)
					}
				})
				if (arr.length == 0) {
					httpRequest.toast("请至少添加一条属性，并填写完整！")
					return false
				}
				uni.$emit('setshuxing',arr)
				uni.navigateBack(1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding-bottom: 150rpx;
	}
	.imgBox{
		width: 36rpx;
		height: 36rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.border_bottom_solid{
		border-bottom: 1rpx solid #EFEFEF;
	}
	.imgDelete{
		width: 24rpx;
		height: 26rpx;
	}
	
	.slys{
		font-size: 24rpx;
	}
	
</style>